package org.springframework.util;

import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

import java.lang.reflect.Method;

@EqualsAndHashCode
@RequiredArgsConstructor
public class MethodKey {

    @Getter
    private final Class<?> declaringClass;
    private final String methodName;

    public static MethodKey of(Method method) {
        Class<?> declaringClass = method.getDeclaringClass();
        String methodName = method.getName();
        return new MethodKey(declaringClass, methodName);
    }

    public static MethodKey of(Class<?> declaringClass,
                               String methodName) {
        return new MethodKey(declaringClass, methodName);
    }

    @Override
    public String toString() {
        return declaringClass.getSimpleName() + "#" + methodName;
    }
}
